home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / games / pd / chess / src.lha / src / gnuchess.h < prev    next >
C/C++ Source or Header  |  1992-09-06  |  18KB  |  605 lines

  1. /*
  2.  * gnuchess.h - Header file for GNU CHESS
  3.  *
  4.  * Copyright (c) 1988,1989,1990 John Stanback
  5.  * Copyright (c) 1992 Free Software Foundation
  6.  *
  7.  * This file is part of GNU CHESS.
  8.  *
  9.  * GNU Chess is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2, or (at your option)
  12.  * any later version.
  13.  *
  14.  * GNU Chess is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with GNU Chess; see the file COPYING.  If not, write to
  21.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23.  
  24. #if !defined(__STDC__) || !defined(MSDOS)
  25. #define const
  26. #endif
  27.  
  28. #ifndef __GNUC__
  29. #define inline
  30. #endif
  31.  
  32. #include <stdio.h>
  33.  
  34. #define SEEK_SET 0
  35. #define SEEK_END 2
  36. #ifdef DEBUG
  37. void
  38. ShowDBLine (char *, short int, short int,
  39.         short int, short int, short int,
  40.         short unsigned int *);
  41.      extern FILE *debugfd;
  42.      extern short int debuglevel;
  43.  
  44. #endif /* DEBUG */
  45.  
  46. #include <ctype.h>
  47.  
  48. #ifdef MSDOS
  49. #include <stdlib.h>
  50. #include <string.h>
  51. #include <time.h>
  52. #define RWA_ACC "r+b"
  53. #define WA_ACC "w+b"
  54. #else
  55. #define RWA_ACC "r+"
  56. #define WA_ACC "w+"
  57. #ifndef AMIGA
  58. #include <sys/param.h>
  59. #endif
  60. #include <sys/types.h>
  61. #ifndef AMIGA
  62. #include <sys/times.h>
  63. #endif
  64. #endif /* MSDOS */
  65. #ifdef NONDSP
  66. #define printz printf
  67. #define scanz scanf
  68. #else
  69. #ifdef AMIGA
  70. #include "amiga/amiterm.h"
  71. #define scanz ami_scanw
  72. extern char *libdir;
  73. #else
  74. #include <curses.h>
  75. #define scanz fflush(stdout), scanw
  76. #endif
  77. #define printz printw
  78. #endif
  79.  
  80. #ifndef AMIGA
  81. #if defined(__STDC__) || defined(MSDOS)
  82. /* <stdio.h> */
  83.      extern int fclose (FILE *);
  84. #ifndef __ultrix /* work around bug in c89 compiler --t.mann */
  85.      extern int fscanf (FILE *, const char *, ...);
  86.      extern int fprintf (FILE *, const char *, ...);
  87. #endif /*__ultrix*/
  88.      extern int fflush (FILE *);
  89.  
  90. /* <stdlib.h> */
  91.      extern int abs (int);
  92.      extern int atoi (const char *);
  93.  
  94. /* <time.h> */
  95.      extern long int time (long int *);
  96.  
  97. /* <string.h> */
  98.      extern void *memset (void *, int, size_t);
  99. #endif
  100. #endif /* AMIGA */
  101.  
  102. /* Piece values */
  103. #define valueP 100
  104. #define valueN 350
  105. #define valueB 355
  106. #define valueR 550
  107. #define valueQ 1100
  108. #define valueK 1200
  109. /* masks into upper 8 bits of ataks array */
  110. #define ctlP 0x4000
  111. #define ctlN 0x2800
  112. #define ctlB 0x1800
  113. #define ctlR 0x0400
  114. #define ctlQ 0x0200
  115. #define ctlK 0x0100
  116. #define ctlBQ 0x1200
  117. #define ctlBN 0x0800
  118. #define ctlRQ 0x0600
  119. #define ctlNN 0x2000
  120. /* attack functions */
  121. #define Patak(c, u) (atak[c][u] > ctlP)
  122. #define Anyatak(c, u) (atak[c][u] > 0)
  123. /* distance function */
  124. #define taxicab(a,b) taxidata[a][b]
  125. /* hashtable flags */
  126. #define truescore 0x0001
  127. #define lowerbound 0x0002
  128. #define upperbound 0x0004
  129. #define kingcastle 0x0008
  130. #define queencastle 0x0010
  131. /* king positions */
  132. #define wking PieceList[white][0]
  133. #define bking PieceList[black][0]
  134. #define EnemyKing PieceList[c2][0]
  135. /* constants */
  136. /* castle moves */
  137. #define BLACKCASTLE    0x3C3E
  138. #define WHITECASTLE    0x0406
  139. #define LONGBLACKCASTLE    0x3C3A
  140. #define LONGWHITECASTLE    0x0402
  141. /* truth values */
  142. #define false 0
  143. #define true 1
  144. /* colors */
  145. #define white 0
  146. #define black 1
  147. #define neutral 2
  148. /* piece code defines */
  149. #define no_piece 0
  150. #define pawn 1
  151. #define knight 2
  152. #define bishop 3
  153. #define rook 4
  154. #define queen 5
  155. #define king 6
  156. #define bpawn 7
  157. /* node flags */
  158. #define pmask 0x0007
  159. #define promote 0x0008
  160. #define cstlmask 0x0010
  161. #define epmask 0x0020
  162. #define exact 0x0040
  163. #define pwnthrt 0x0080
  164. #define check 0x0100
  165. #define capture 0x0200
  166. #define draw 0x0400
  167. /* move symbols */
  168. #define pxx (CP[2])
  169. #define qxx (CP[1])
  170. #define rxx (CP[4])
  171. #define cxx (CP[3])
  172. /* for everything that can't use the above */
  173. #define Qxx " pnbrqk"
  174. #define Pxx " PNBRQK"
  175. #define Cxx "abcdefgh"
  176. #define Rxx "12345678"
  177. /***************************************************************************/
  178. /***************** Table limits ********************************************/
  179. /*
  180.  * ttblsz must be a power of 2. Setting ttblsz 0 removes the transposition
  181.  * tables.
  182.  */
  183. #if defined(MSDOS) || defined(AMIGA)
  184. #define vttblsz 0 /*(1 << 11)*/
  185. #else
  186. #define vttblsz (1 << 17)
  187. #define huge
  188. #endif /* MSODS */
  189.  
  190. #define ttblsz vttblsz
  191. #define TREE 1500        /* max number of tree entries */
  192. #define MAXDEPTH 35        /* max depth a search can be carried */
  193. #define MINDEPTH 3        /* min search depth =1 (no hint), >1 hint */
  194. #define MAXMOVES 400        /* max number of half moves in a game */
  195. #ifdef AMIGA
  196. #define BOOKSIZE 10000        /* Number of unique position/move combinations allowed */
  197. #else
  198. #define BOOKSIZE 30000        /* Number of unique position/move combinations allowed */
  199. #endif
  200. #define CPSIZE 226        /* size of lang file max */
  201. /***************** tuning paramaters **********************************************/
  202. #define CHKDEPTH 1        /* always look forward CHKDEPTH half-moves if in check */
  203. #define DEPTHBEYOND 11        /* Max to go beyond Sdepth */
  204. #define HASHDEPTH 4        /* depth above which to use HashFile */
  205. #define HASHMOVELIMIT 40    /* Use HashFile only for this many moves */
  206. #define PTVALUE 2000            /* material value below which pawn threats at 5 & 3 are used */
  207. #define ZDEPTH 3        /* depth beyond which to check ZDELTA for extra time */
  208. #define ZDELTA 10        /* score delta per ply to cause extra time to be given */
  209. #define ZNODES 1000        /* check the time every ZNODES positions */
  210. #define MAXTCCOUNT 4        /* max number of time clicks per search */
  211. #define MINSEARCHPCT 10        /* must have looked at MINSEARCHPCT moves on a ply on a timeout */
  212. #define SCORETIME -50        /* score below which to add search time */
  213. #define SCORESPLIM 8        /* Score space doesn't apply after this stage */
  214. #define HISTORYLIM 155        /* Max value of history killer */
  215. #define EWNDW 10        /* Eval window to force position scoring at depth greater than Sdepth + 2 */
  216. #define WAWNDW 90        /* alpha window when computer white*/
  217. #define WBWNDW 90        /* beta window when computer white*/
  218. #define BAWNDW 90        /* alpha window when computer black*/
  219. #define BBWNDW 90        /* beta window when computer black*/
  220. #define BXWNDW 90        /* window to force position scoring at lower */
  221. #define WXWNDW 90        /* window to force position scoring at lower */
  222. #define DITHER 2        /* 1+max amount random can alter a pos value */
  223. #define BBONUS 2        /* points per stage value of B increases */
  224. #define RBONUS 6        /* points per stage value of R increases */
  225. #define KINGPOSLIMIT ( -1)    /* King positional scoring limit */
  226. #define KINGSAFETY  16
  227. #define MAXrehash (6)
  228.  
  229. #if defined AG0
  230. #define WHITEAG0
  231. #define BLACKAG0
  232.  
  233. #elif defined AG1
  234. #define WHITEAG1
  235. #define BLACKAG1
  236.  
  237. #elif defined AG2
  238. #define WHITEAG2
  239. #define BLACKAG2
  240.  
  241. #elif defined AG3
  242. #define WHITEAG3
  243. #define BLACKAG3
  244.  
  245. #elif defined AGB
  246. #define WHITEAG2
  247. #define BLACKAG2
  248.  
  249. #elif defined AG4
  250. #define WHITEAG4
  251. #define BLACKAG4
  252. #endif
  253. /************************* parameters for Opening Book *********************************/
  254. #define BOOKBITS 10        /* # bits for hashtable to book moves */
  255. #define BOOKFAIL 20000        /* if no book move found for BOOKFAIL turns stop using book */
  256. #define BOOKRAND 1000        /* used to select an opening move from a list */
  257. #define BOOKENDPCT 500        /* 50 % chance a BOOKEND will stop the book */
  258. #define DONTUSE -32768        /* flag move as don't use */
  259. /*************************** Book access defines ****************************************/
  260. #define BKTBLSIZE (2<<BOOKBITS)
  261. #define BOOKMASK (BKTBLSIZE - 1)
  262. #define SIDEMASK 0x1
  263. #define BOOKEND 0x2        /* means this is the last move of an opening */
  264. #define BADMOVE 0x8000        /* means this is a bad move in this position */
  265. /****************************************************************************************/
  266.      struct hashval
  267.      {
  268.        unsigned long key, bd;
  269.      };
  270.      struct hashentry
  271.      {
  272.        unsigned long hashbd;
  273.        unsigned short mv;
  274.        unsigned char flags, depth;    /* char saves some space */
  275.        short score;
  276. #ifdef HASHTEST
  277.        unsigned char bd[32];
  278. #endif /* HASHTEST */
  279.  
  280.      };
  281.  
  282. #ifdef HASHFILE
  283.  
  284. /*